<%--
  Created by IntelliJ IDEA.
  User: 风间琉璃
  Date: 2021/4/21
  Time: 15:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加疫苗接种预约信息</title>
    <script src="js/jquery-1.8.3.js"></script>
</head>
<body>
    <form id="form-booking"action="javascript:void(0)">
        <table>
            <tr>
                <td><h1>添加疫苗接种预约信息</h1></td>
            </tr>
            <tr>
                <td>预约人姓名（*）</td>
                <td><input id="userName" name="userName"><span class="check"></span></td>
            </tr>
            <tr>
                <td>预约人身份证号（*）</td>
                <td><input name="cardId" cardId="cardId" id="cardId"><span class="check"></span></td>
            </tr>
            <tr>
                <td>预约接种日期（*）</td>
                <td><input id="bookingDate" name="bookingDate"><span class="check"></span></td>
            </tr>
            <tr>
                <td><button type="submit" id="add">提交</button></td>
            </tr>
        </table>
    </form>
<script>

    $(function () {
        $("#cardId").blur(function () {
            var cardId = $(this).val();
            var $next = $(this).next();
            $.get("BookingServlet?opr=che","cardId="+cardId,function (data) {
                $next.html(data);
            })
        })
        $("#form-booking").submit(function () {
            if ($("#userName").val() == "" || $("#userName").val() == null ||
                $("#cardId").val() == "" || $("#cardId").val() == null ||
                $("#bookingDate").val() == "" || $("#bookingDate").val() == null){
                alert("请填写完整！");
                return ;
            }
            if ($(".check").text() == "该人员已接种或已预约疫苗"){
                alert("请换个身份证号再预约！");
                return ;
            }
            var $inputs = $(this).find(":input");
            var queryString = $inputs.serialize();
            $.get("BookingServlet?opr=add", queryString, function (data) {
                console.log(data);
                if (1 == data){
                    alert("添加成功！");
                    location.href="BookingServlet";
                }else {
                    alert("添加失败！");
                }
            })
        })
    })
</script>
</body>
</html>
